﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace Chapter1_19
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            




        }

        public Task SleepAsyncA(int timeout)
        {
            return Task.Run(() => Thread.Sleep(timeout));
        }

        public Task SleepAsyncB(int timeout)
        {
            TaskCompletionSource<bool> tcs = null;
            var t = new Timer(delegate { tcs.TrySetResult(true); },null,-1,-1);
            tcs = new TaskCompletionSource<bool>(t);
            t.Change(timeout,-1);
            return tcs.Task; 
        }
            
    }
}
